package sdk.webview.fmc.com.fmcsdk.check.adapter;


import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

import sdk.webview.fmc.com.fmcsdk.R;
import sdk.webview.fmc.com.fmcsdk.check.bean.ImageSelectBean;
import sdk.webview.fmc.com.fmcsdk.util.GlideImageLoader;
import sdk.webview.fmc.com.fmcsdk.util.KLog;

public class ImageSelectAdapter extends BaseQuickAdapter<ImageSelectBean, BaseViewHolder> {
    private boolean isUpload;

    public ImageSelectAdapter(@Nullable List<ImageSelectBean> data) {
        super(R.layout.item_select_img, data);
    }


    @Override
    protected void convert(@NotNull BaseViewHolder holder, ImageSelectBean item) {
        ImageView iv_view = holder.getView(R.id.iv_view);
        holder.setGone(R.id.iv_pay, false);
        LinearLayout ll_add_pic = holder.getView(R.id.ll_add_pic);
        holder.setGone(R.id.ll_fram,true);
        if (isUpload) {
            if (item.getType() == 0) {
                holder.setGone(R.id.ll_fram,false);
                iv_view.setVisibility(View.GONE);
                ll_add_pic.setVisibility(View.GONE);
            } else {
                ll_add_pic.setVisibility(View.GONE);
                iv_view.setVisibility(View.VISIBLE);
                holder.setGone(R.id.iv_pay, item.getImg().contains("mp4"));
                KLog.e(item.getImg());
                GlideImageLoader.loadImg(mContext, item.getImg(), iv_view);
            }
        } else {
            if (item.getType() == 0) {
                iv_view.setVisibility(View.GONE);
                ll_add_pic.setVisibility(View.VISIBLE);
            } else {
                ll_add_pic.setVisibility(View.GONE);
                iv_view.setVisibility(View.VISIBLE);
                holder.setGone(R.id.iv_pay, item.getImg().contains("mp4"));
                KLog.e(item.getImg());
                GlideImageLoader.loadImg(mContext, item.getImg(), iv_view);
            }
        }
        holder.addOnClickListener(R.id.iv_view);
        holder.addOnClickListener(R.id.ll_add_pic);
        holder.addOnLongClickListener(R.id.iv_view);
    }

    public String getSelectImgNum() {
        int num = 0;
        for (int i = 0; i < getData().size(); i++) {
            if (getData().get(i).getType() != 0) {
                num = num + 1;
            }
        }
        return num + "";
    }


    public void addType00() {
        boolean isHave = false;
        for (int i = 0; i < getData().size(); i++) {
            if (getData().get(i).getType() == 0) {
                isHave = true;
            }
        }
        if (!isHave && getData().size() < 9) {
            getData().add(0, new ImageSelectBean("", 0));
        }
        notifyDataSetChanged();

    }

}
